//
//  FirstViewController.swift
//  SwiftDemo
//
//  Created by Jason on 15/5/27.
//  Copyright (c) 2015年 Jason Jiang. All rights reserved.
//

import UIKit

/**
做代理的实现
**/

class FirstViewController: UIViewController ,TouchViewDelegate{

    
    var dic = Dictionary<String,AnyObject>()
    var list = Array<AnyObject>()

    override func loadView() {
        //
        super.loadView();
        self.view.backgroundColor = UIColor.whiteColor();
        
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "代理实现";

        // Do any additional setup after loading the view.
        let tv:TouchView = TouchView ();
        tv.delegate = self;
        tv.frame = CGRectMake(0, 64, CGRectGetWidth(self.view.frame), 200);
        tv.backgroundColor = UIColor.whiteColor()
        self.view.addSubview(tv);
        
        /**
        处理多线程
          **/
        
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    //protocal
    
    func viewTouched(touchView: TouchView) {
        
        NSLog("fdsfas%@", touchView);
//        dic.updateValue("Jhy", forKey: "jhy")
        
        dic["jhy"] = "JHY"
        dic["jjj"] = touchView;
        dic["JHY"] = nil
        list.append("fdsfsdfaasd")
        list.append("fdsfdsfdsfsdsafasdfas")

        
        for _ in list {
            print(list[1])
            NSLog("opopop%@", list[1] as! String)
        }
        
        
        let rect = CGRectMake(0, 0, 50, 2)
        let area = rect.area;
        NSLog("the area is %f", area)
        
        //extension 將非字符串處理成字符串
        let str2  =  NSString().stringWithAbnomal(6666)
        let str3 = self.backDatafromStr("ddd")
        NSLog("the normal function%@", str3)
        NSLog("the extension function%@", str2)
        
        let threadVC = ThreadViewController ()
        self.navigationController?.pushViewController(threadVC, animated: true)
        
        
    }

    //normal function
    func backDatafromStr(str : String) -> String{
        
        
        return "jhy"
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
